<template>
    <!-- 病例管理-住院建议书 -->
    <div class="inpatient-table">
        <yx-table :is-fit="false" :table-data="tableData" :columns="columns" :page-obj="pageObj" :loading="loading" :tableHeightDefault="600">
            <template slot="patientSex" slot-scope="scope">
                <div>{{scope.scope.patientSex | sexFilter}}</div>
            </template>
            <template slot="isInvalidation" slot-scope="scope">
                <div>{{scope.scope.isInvalidation === "0" ? "否" : "是"}}</div>
            </template>
            <template slot="operate" slot-scope="scope">
                <div class="operate-btn">
                    <div>
                        <el-button style="color: #006DB8;" size="small" type="text" @click="preview(scope.scope)">
                            查看打印
                        </el-button>
                    </div>
                    <div v-if="$authInfo.getAuthType() == 'D' && scope.scope.isInvalidation == '0'">
                        <el-button style="color: #E53B46;" size="small" type="text" @click="revocationHospitalization(scope.scope)">
                            撤销
                        </el-button>
                    </div>
                </div>
            </template>
        </yx-table>

        <pdf-dialog ref="pdfDialog"></pdf-dialog>

        <!--撤销弹框 start-->
        <el-dialog style="text-align:center;" title="撤销原因" width="600" :visible.sync="revocationDialog" @close="closeDialog('revocationDialog')" :close-on-click-modal="false" :close-on-press-escape="false">
            <el-input v-model="reasonsInput" style="resize:none;" type="textarea" :autosize="{ minRows: 2, maxRows: 8}"></el-input>
            <div style="margin-top:20px;">
                <el-button @click="closeDialog('revocationDialog')">取 消</el-button>
                <el-button type="primary" @click="revocation">确 定</el-button>
            </div>
        </el-dialog>
        <!--弹框 end -->
    </div>
</template>

<script>
    import yxTable from '@/components/yxtable/yx-table'
    import pdfDialog from '@/components/chatroom/view-pdf';
    export default {
        components: {
            yxTable,
            pdfDialog
        },
        props: {
            queryList: {
                type: Object,
                default () {
                    return {}
                }
            },
        },
        data() {
            return {
                columns: [
                    { label: '问诊患者', prop: 'patientName' },
                    { label: '性别', slot: 'patientSex' },
                    { label: '联系电话', prop: 'patientPhone' },
                    { label: '办理问诊日期', prop: 'acceptsTime' },
                    { label: '办理协助医生', prop: 'trueName' },
                    { label: '申请入住医院', prop: 'hospitalizationHospital' },
                    { label: '申请科室', prop: 'hospitalizationDepartment' },
                    { label: '诊断', prop: 'diagnosisDescribe' },
                    { label: '是否撤销', slot: 'isInvalidation' },
                    { label: '撤销原因', prop: 'reasonsInvalidation' },
                    { label: '操作', slot: 'operate' },
                ], // 操作列
                loading: false,
                pageObj: {
                    size: 10,
                    total: 0,
                    currentPage: 1,
                    func: (currentPage) => {
                        this.pageTurning(currentPage)
                    },
                    handleSizeChange: (size) => {
                        this.sizeChange(size)
                    }
                },
                tableData: [],
                revocationDialog: false,
                reasonsInput: '',
                revocationId: null,
            }
        },
        mounted() {
            this.getHospitalizationList();
        },
        methods: {
            preview(e) {
                let params = {
                    id: e.id,
                    resource: 1
                };

                this.$refs.pdfDialog && this.$refs.pdfDialog.onOpen(params);
            },
            // 数据查询
            queryData() {
                this.getHospitalizationList();
            },
            pageTurning(currentPage) {
                this.pageObj.currentPage = currentPage;
                this.getHospitalizationList();
            },
            sizeChange(size) {
                this.pageObj.size = size;
                this.getHospitalizationList();
            },
            getHospitalizationList() {
                this.loading = true;
                let params = {
                    current: this.pageObj.currentPage,
                    size: this.pageObj.size,
                    endDate: this.queryList.time[1] || '',
                    startDate: this.queryList.time[0] || '',
                    patientName: this.queryList.patientName,
                    patientPhone: this.queryList.patientPhone
                }
                let apiName = this.$authInfo.getAuthType() == 'D' ? 'getHospitalizationList' : 'getPatientHospitalizationList';
                this.$ajax[apiName](params).then(res => {
                    this.loading = false;
                    let { code, data } = res;
                    if (code === 1) {
                        this.tableData = data.list
                        this.pageObj.total = data.total
                    }
                    // console.log(data)
                }).catch(err => {
                    this.loading = false;
                });
            },
            revocationHospitalization(row) {
                this.revocationDialog = true;
                this.revocationId = row.id
            },
            closeDialog() {
                this.revocationDialog = false;
                this.reasonsInput = ''
            },
            revocation() { //撤回
                let para = {
                    webToken: this.$authInfo.webToken(),
                    reasonsInvalidation: this.reasonsInput,
                    id: this.revocationId
                }
                this.$ajax.revocationHospitalization(para).then(res => {
                    this.$message({
                        message: res.msg,
                        type: 'success',
                    })
                    this.getHospitalizationList();
                    this.revocationDialog = false;
                }).catch(err => {
                    this.$message({
                        message: err.msg,
                        type: 'error'
                    })
                })
            },
        }
    }
</script>

<style lang="scss">
    .inpatient-table {
        /deep/ .el-button--small {
            padding: 5px 15px;
        }
    }
</style>